home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0793 / STUFFBUF.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-01  |  3KB  |  96 lines

  1. (*─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 295 of 370
  3. From : Keld R. Hansen                      2:234/10.0           25 Jun 93  21:36
  4. To   : Bryce Ostenson                      1:282/4028.0
  5. Subj : Stuffing Keyboard Buffer
  6. ────────────────────────────────────────────────────────────────────────────────
  7. In a message dated 10 Jun 93, Bryce Ostenson (1:282/4028.0) wrote:
  8.  
  9.  > You don't need to know assembler, just to understand how to call an
  10.  > interrupt from pascal. It's simple... [...] Begin        Regs.AH := $05;  {
  11.  > function $05 of interrupt $16 }        Regs.CH := ScanCode;        Regs.CL
  12.  > := AsciiCode;        Intr($16,Regs);        If Regs.AL = 0 then StuffKey :=
  13.  > True else StuffKey := False; End;
  14.  
  15. And this one will *only* work on ATs and XTs after a certain date! A universal
  16. routine follows:*)
  17.  
  18. PROCEDURE PokeKey; NEAR; ASSEMBLER;
  19.   ASM
  20.                 PUSH    AX
  21.                 PUSH    BX
  22.                 PUSH    CX
  23.                 PUSH    ES
  24.                 MOV     CX,AX
  25.                 {$IFDEF DPMI }
  26.                         MOV     AX,0900h
  27.                         INT     31h
  28.                         PUSH    AX
  29.                 {$ELSE  }
  30.                         PUSHF
  31.                         CLI
  32.                 {$ENDIF }
  33.                 MOV     AX,SEG Seg0040
  34.                 MOV     ES,AX
  35.                 MOV     ES,ES:Seg0040
  36.                 MOV     BX,ES:[001Ch]
  37.                 MOV     AX,BX
  38.                 INC     AX
  39.                 INC     AX
  40.                 CMP     AX,ES:[0082h]
  41.                 JNE     @NoWrap
  42.                 MOV     AX,ES:[0080h]
  43.     @NoWrap:    CMP     AX,ES:[001Ah]
  44.                 JE      @Ovflw
  45.                 MOV     ES:[001Ch],AX
  46.                 MOV     ES:[BX],CX
  47.     @Ovflw:     {$IFDEF DPMI }
  48.                         POP     AX
  49.                         INT     31h
  50.                 {$ELSE  }
  51.                         POPF
  52.                 {$ENDIF }
  53.                 POP     ES
  54.                 POP     CX
  55.                 POP     BX
  56.                 POP     AX
  57.   END;
  58.  
  59. PROCEDURE PutKeyInKbdBuf(Key : WORD); ASSEMBLER;
  60.   ASM
  61.                 MOV     AX,Key
  62.                 CALL    PokeKey
  63.   END;
  64.  
  65. PROCEDURE PutCharInKbdBuf(C : CHAR); ASSEMBLER;
  66.   ASM
  67.                 XOR     AH,AH
  68.                 MOV     AL,C
  69.                 CALL    PokeKey
  70.   END;
  71.  
  72. PROCEDURE PutStrInKbdBuf(CONST S : STRING); ASSEMBLER;
  73.   ASM
  74.                 PUSH    DS
  75.                 LDS     SI,S
  76.                 CLD
  77.                 XOR     AH,AH
  78.                 LODSB
  79.                 MOV     CX,AX
  80.                 JCXZ    @OUT
  81.     @LOOP:      LODSB
  82.                 CALL    PokeKey
  83.                 LOOP    @LOOP
  84.     @OUT:       POP     DS
  85.   END;
  86.  
  87. PROCEDURE ClearKbdBuf; ASSEMBLER;
  88.   ASM
  89.                 MOV     ES,Seg0040
  90.                 MOV     AX,ES:[001Ah]
  91.                 MOV     ES:[001Ch],AX
  92.   END;
  93.  
  94. And it will even work with keyboard extenders if these extenders conform to the
  95. BIOS specification (unlike a lot of other keyboard stuffers I have seen in my
  96. time...)